<?php
namespace App\Http\Controllers\Webapi;
use App\Http\Controllers\Controller;
use App\Common\ApiData;
use App\Models\V1\ChapterModel;
use App\Models\V1\DrpModel;
use App\Models\V1\MemberModel;
use Illuminate\Http\Request;

class OfficerController extends Controller{

    public  function __constructor(){
        parent::__constructor();
    }



    //学习官信息
    public function officer_info(Request $request){

        $userId     = $request->input('userId');
        $chapterId  = $request->input('chapterId');
        $apiData    = new ApiData();

        $memberModel    = new MemberModel();
        $memberInfo     = $memberModel->get_member_info_by_id($userId);

        $chapterModel   = new ChapterModel();


        $drpModel       = new DrpModel();

        $drpInfo        = $chapterModel->get_chapter_officer_info($userId);

        $empDrp              = new \stdClass();
        $empDrp->YourName    = "无";
        $empDrp->FilePath1   = change_member_head_img('');

        //获得向上两级的学习官
        $parentsDrp = $drpModel->get_parent_drp_list($userId,2);
        $parentsNum = count($parentsDrp);

        if($parentsNum == 0){
            $parentDrpInfo      = $empDrp;
            $grandparentDrpInfo = $empDrp;
        }elseif($parentsNum == 1){
            $parentDrpInfo      = $parentsDrp[0];
            $grandparentDrpInfo = $empDrp;
        }else{
            $parentDrpInfo      = $parentsDrp[0];
            $grandparentDrpInfo = $parentsDrp[1];
        }

        return $apiData
            ->set_data('officerInfo',$memberInfo)
            ->set_data('drpInfo',$drpInfo)
            ->set_data('parentDrpInfo',$parentDrpInfo)
            ->set_data('grandparentDrpInfo',$grandparentDrpInfo)
            ->send(200,'ok');
    }




}